package day0526;

import java.util.Arrays;
import java.util.Comparator;

public class Test2 {
    public static void main(String[] args) {
        int[] a1={4,7,2,1,9};
        Arrays.sort(a1);//升序

        Integer[] a2={4,7,2,1,9};
        Arrays.sort(a2, new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });//降序


        String[]  ss={"ABC",  "DEF" ,  "rrrrr"};
        Arrays.sort(ss, new Comparator<String>() {
            public int compare(String o1, String o2) {
                return  o2.length()-o1.length();
            }
        });



        Double[]    c={7.2,  4.631,   4.632,   2.8,   9.0};
        Arrays.sort(c, new Comparator<Double>() {
            public int compare(Double o1, Double o2) {
                return  (int)  ((o2-o1)*10000);
            }
        });
        System.out.println(Arrays.toString(c));

        //插入排序。
        for (int rightIndex = 1; rightIndex < c.length; rightIndex++) {
            int leftIndex = rightIndex-1;
            double t=c[rightIndex];
            while(leftIndex>=0 && t<c[leftIndex]){
                c[leftIndex+1]=c[leftIndex];//将[leftIndex]往[leftIndex+1]复制
                leftIndex--;
            }
            c[leftIndex+1]=t;
        }
        System.out.println(Arrays.toString(c));


        /*//插入排序
        for (int rightIndex = 1; rightIndex < a.length; rightIndex++) {
            int leftIndex=rightIndex-1;
            int temp=a[rightIndex];
            //左边部分的元素序号要>=0  &&   右边比较的元素如果小于左边部分的元素就继续比较(直到右边比较的元素大就结束)
            while(leftIndex>=0 && a[leftIndex]>temp){
                a[leftIndex+1]=a[leftIndex];//将第leftIndex复制到leftIndex+1
                leftIndex--;//左边序号leftIndex--
            }
            a[leftIndex+1]=temp;//将temp元素放到a[leftIndex+1]
        }
        System.out.println(Arrays.toString(a));*/
    }
}


